package com.wc.算法提高课.B第二章_搜索.DFS之剪枝与优化.小猫爬山;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/28 23:09
 * @description https://www.acwing.com/problem/content/description/167/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 20;
    static int[] sum = new int[N];
    static int[] w = new int[N];
    static int n, m, ans = N;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 0; i < n; i++) w[i] = sc.nextInt();
        Arrays.sort(w, 0, n);
        for (int i = 0, j = n - 1; i < j; i++, j--) {
            int tmp = w[i];
            w[i] = w[j];
            w[j] = tmp;
        }
        dfs(0, 0);
        out.println(ans);
        out.flush();
    }

    static void dfs(int u, int k) {
        if (k >= ans) return;
        if (u == n) {
            ans = k;
            return;
        }
        for (int i = 0; i < k; i++) {
            if (sum[i] + w[u] <= m) {
                sum[i] += w[u];
                dfs(u + 1, k);
                sum[i] -= w[u];
            }
        }
        sum[k] = w[u];
        dfs(u + 1, k + 1);
        sum[k] = 0;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
